package com.brzjomo.secretiveworld;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.brzjomo.secretiveworld.init.ModBiomeTypes;
import com.brzjomo.secretiveworld.init.ModBlocks;
import com.brzjomo.secretiveworld.init.ModContainerTypes;
import com.brzjomo.secretiveworld.init.ModDimensionTypes;
import com.brzjomo.secretiveworld.init.ModEntityTypes;
import com.brzjomo.secretiveworld.init.ModFeatures;
import com.brzjomo.secretiveworld.init.ModItems;
import com.brzjomo.secretiveworld.init.ModSounds;
import com.brzjomo.secretiveworld.init.ModTileEntityTypes;
import com.brzjomo.secretiveworld.object.item.ModSpawnEggItem;
import com.brzjomo.secretiveworld.world.gen.ModEntityGen;
import com.brzjomo.secretiveworld.world.gen.ModOreGen;
import com.brzjomo.secretiveworld.world.gen.ModStructureGen;

import net.minecraft.entity.EntityType;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import software.bernie.example.GeckoLibMod;
import software.bernie.geckolib3.GeckoLib;

@Mod(SecretiveWorld.MODID)
@Mod.EventBusSubscriber(modid = SecretiveWorld.MODID, bus = Bus.MOD)
public class SecretiveWorld {
	// 设置一个常量MODID，需要跟META-INF下mods.toml中的modid保持一致
	public static final String MODID = "secretiveworld";
	
	public static final Logger LOGGER = LogManager.getLogger(MODID);

	static {
		GeckoLibMod.DISABLE_IN_DEV = false;
	}
	
	public SecretiveWorld() {

		final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
		modEventBus.addListener(this::LoadCompleteEvent);
		modEventBus.addListener(this::setup);
		
		GeckoLib.initialize();
		
		ModSounds.SOUNDS.register(modEventBus);
		ModItems.ITEMS.register(modEventBus);
		ModBlocks.BLOCKS.register(modEventBus);
		ModTileEntityTypes.TILE_ENTITY_TYPES.register(modEventBus);
		ModContainerTypes.CONTAINER_TYPES.register(modEventBus);
		ModEntityTypes.ENTITY_TYPES.register(modEventBus);
		ModFeatures.FEATURES.register(modEventBus);
		ModBiomeTypes.BIOMES.register(modEventBus);
		ModDimensionTypes.DIMENSIONS.register(modEventBus);
    }

	private void setup(final FMLCommonSetupEvent event) {
		ModEntityGen.registerPlacementTypes();
		ModEntityGen.entitySpawn();
	}
	
	@SubscribeEvent
	public static void onRegisterBiomes(final RegistryEvent.Register<Biome> event) {
		ModBiomeTypes.registerBiomes();
	}
	
    @SubscribeEvent
	public void LoadCompleteEvent(final FMLLoadCompleteEvent event) {
    	ModOreGen.oreGen();
    	ModStructureGen.structureGen();
    }
    
    @SubscribeEvent
	public static void onRegisterEntities(final RegistryEvent.Register<EntityType<?>> event) {
		ModSpawnEggItem.initSpawnEggs();
	}
}
